<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
  <script src="../js/vue.js"></script>
</head>

<body>
  <div id="root">
    <school></school>
  </div>
  <script>
    const school = Vue.extend({
      template: `
        <div>
            <h2>名称：{{name}}</h2>
            <button @click="showX">点我输出x</button>
        </div>
        `,
      data() {
        return {
          name: '北京',
        };
      },
      methods: {
        showX() {
          console.log(this.x);
        },
      },
    });
    new Vue({
      el: '#root',
      data: {
        msg: 'hello',
      },
      components: { school },
    });

    console.log(
      'school.prototype.__proto__ === Vue.prototype 相等吗？',
      school.prototype.__proto__ === Vue.prototype
    );

    // 定义一个构造函数
    function Demo() {
      this.a = 1;
      this.b = 2;
    }
    // 创建一个Demo的实例对象
    const d = new Demo();

    console.log(Demo.prototype); // 显示原型属性(函数才会拥有)
    console.log(d.__proto__); // 隐式原型属性(对象上有，指向自己缔造者的原型对象)

    console.log(Demo.prototype === d.__proto__);

    // 通过显示原型属性操作原型对象，追加一个x属性，值为99
    Demo.prototype.x = 99;

    console.log('@', d.__proto__.x);
  </script>
</body>

</html>